package com.projectsexception.festivales.provider.handlers;

import java.util.HashMap;
import java.util.Map;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import com.projectsexception.festivales.provider.model.Stage;
import com.projectsexception.festivales.provider.util.SAXHandlerUtil;

public class StagesHandler extends DefaultHandler {
    
    private static final String STAGE_ELEMENT = "stage";
    private static final String ID_ATTRIBUTE = "id";
    private static final String NAME_ATTRIBUTE = "name";
    
    private Map<String, Stage> stages;

    @Override
    public void startDocument() {
        stages = new HashMap<String, Stage>();
    }

    @Override
    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
        String s = SAXHandlerUtil.getElementName(localName, qName);
        if (s.equals(STAGE_ELEMENT)) {            
            Stage stageInfo = new Stage();
            String id = attributes.getValue(ID_ATTRIBUTE);
            stageInfo.setId(id);
            stageInfo.setName(attributes.getValue(NAME_ATTRIBUTE));
            stages.put(id, stageInfo);
        }
    }

    public Map<String, Stage> getResult() {
        return stages;
    }

}
